/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Com.view;

import Com.perpus.Anggota;
import Com.perpus.Perpustakaan;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PanelTambahAnggota extends JPanel {

    private JLabel labelKodeAnggota;
    private JTextField textKodeAnggota;
    private JLabel labelNama;
    private JTextField textNama;
    private JButton tombolSimpan;
    private JButton tombolBatal;

    public PanelTambahAnggota() {
        labelKodeAnggota = new JLabel("Kode Anggota");
        labelNama = new JLabel("Nama");
        textKodeAnggota = new JTextField(50);
        textNama = new JTextField(100);
        tombolBatal = new JButton("Batal");
        tombolSimpan = new JButton("Simpan");

        this.setLayout(null);
        add(labelKodeAnggota);
        labelKodeAnggota.setBounds(10, 0, 100, 70);
        add(textKodeAnggota);
        textKodeAnggota.setBounds(100, 30, 150, 20);
        add(labelNama);
        labelNama.setBounds(10, 30, 100, 70);
        add(textNama);
        textNama.setBounds(100, 60, 300, 20);

        JPanel c = new JPanel();
        tombolBatal = new JButton("Batal");
        tombolBatal.setBounds(100, 100, 80, 20);
         tombolBatal.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
               System.exit(0);
            }
        });
        c.add(tombolBatal);
        this.add(tombolBatal);

        JPanel c1 = new JPanel();
        tombolSimpan = new JButton("Simpan");
        tombolSimpan.setBounds(200, 100, 80, 20);
          tombolSimpan.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
               Anggota ang = new Anggota();
                  try {
                      ang.setIdAnggota(textKodeAnggota.getText());
                  } catch (Exception ex) {
                      Logger.getLogger(PanelTambahAnggota.class.getName()).log(Level.SEVERE, null, ex);
                  }
               ang.setNama(textNama.getText());
               Perpustakaan.tambahAnggota(ang);
                 JOptionPane.showMessageDialog(null,"Anggota Baru \n"+"Id Anggota : "+ang.getIdAnggota()+"\n"
                        +"Nama : "+ang.getNama());
               
            }
        });
        c1.add(tombolSimpan);
        this.add(tombolSimpan);


    }
}
